/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import ClasesAModificar.*;
import javax.swing.JOptionPane;
import src.InfoMedianteID;

/**
 *
 * @author Strauzen
 */
public class VentanaConsultaEleccion extends javax.swing.JFrame {

    Ventana1 v1;
    int padre = -1; //0 documento, 1 personaje, 2 colectivo, 3 acontecimiento
    
    /**
     * Creates new form VentanaConsultaEleccion
     */
    public VentanaConsultaEleccion(Ventana1 v1) {
        this.v1 = v1;
        initComponents();
    }
    
    public void modificarTexto(String s)
    {
        this.jTextArea_vanSeleccion.setText(s);
    }
    
    public void setVisibleVCETipo(boolean v){
        this.jComboBox_VCETipo.setVisible(v);
    }
    
    public void setPadre(int p){
        padre = p;
    }
    
    public int getPadre(){
        return padre;
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton_vanAnadir = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea_vanSeleccion = new javax.swing.JTextArea();
        jLabel_vanSeleccion = new javax.swing.JLabel();
        jTextField_vanSeleccion = new javax.swing.JTextField();
        jComboBox_VCETipo = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jButton_vanAnadir.setText("Elejir");
        jButton_vanAnadir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_vanAnadirMouseClicked(evt);
            }
        });

        jTextArea_vanSeleccion.setColumns(20);
        jTextArea_vanSeleccion.setEditable(false);
        jTextArea_vanSeleccion.setRows(5);
        jScrollPane2.setViewportView(jTextArea_vanSeleccion);

        jLabel_vanSeleccion.setText("Indice que desea consultar:");

        jComboBox_VCETipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Documento", "Personaje", "Colectivo", "Acontecimiento" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel_vanSeleccion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_vanSeleccion, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                        .addComponent(jComboBox_VCETipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton_vanAnadir))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_vanAnadir)
                    .addComponent(jLabel_vanSeleccion)
                    .addComponent(jTextField_vanSeleccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox_VCETipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_vanAnadirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_vanAnadirMouseClicked
        // TODO add your handling code here:
        try {
            String mostrar ="";
            Integer.parseInt(this.jTextField_vanSeleccion.getText());
            if(padre == 0 || this.jComboBox_VCETipo.getSelectedIndex() == 0)
            {
                DocumentoModificar DM = InfoMedianteID.dameDocumento(Integer.valueOf(jTextField_vanSeleccion.getText()));
                mostrar = ClasesAModificarToString.DMtoSTRING(DM);
            }else 
                if(padre == 1 || this.jComboBox_VCETipo.getSelectedIndex() == 1)
            {
                PersonajeMoficar PM = InfoMedianteID.damePersonaje(Integer.valueOf(jTextField_vanSeleccion.getText()));
                mostrar = ClasesAModificarToString.PMtoSTRING(PM);
            }else
                if(padre == 2 || this.jComboBox_VCETipo.getSelectedIndex() == 2)
            {
                ColectivoModificar CM = InfoMedianteID.dameColectivo(Integer.valueOf(jTextField_vanSeleccion.getText()));
                mostrar = ClasesAModificarToString.CMtoSTRING(CM);
            }else
                if(padre == 3 || this.jComboBox_VCETipo.getSelectedIndex() == 3)
            {
                AcontecimientoModificar AM = InfoMedianteID.dameAcontecimiento(Integer.valueOf(jTextField_vanSeleccion.getText()));
                mostrar = ClasesAModificarToString.AMtoSTRING(AM);
            }
            VentanaConsultaResultado vcr = new VentanaConsultaResultado(v1);
            vcr.setVisible(true);
            vcr.setTexto(mostrar);
            this.setVisible(false);
            this.dispose();
            
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Por favor introduzca el numero que represente el indice que desea añadir");
        }
    }//GEN-LAST:event_jButton_vanAnadirMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_vanAnadir;
    private javax.swing.JComboBox jComboBox_VCETipo;
    private javax.swing.JLabel jLabel_vanSeleccion;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea_vanSeleccion;
    private javax.swing.JTextField jTextField_vanSeleccion;
    // End of variables declaration//GEN-END:variables
}
